<?php

namespace App\Http\Requests\Admin\Panx\Product;

use App\Http\Requests\ApiRequest;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

/**
 * @property string name
 * @property string const
 */
class ProductTagUpdateRequest extends ApiRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $id = last(explode('/', $this->url()));

        return [
            'name' => ['required', 'string', 'max:'.self::MAX_STRING, Rule::unique('product_tags', 'name')->ignore($id)],
            'const'=> ['required', 'string', 'max:'.self::MAX_STRING, 'regex:/^[0-9A-Za-z-_\s]+$/', Rule::unique('product_tags', 'const')->ignore($id)]
        ];
    }

    /**
     * @return array
     */
//    public function messages()
//    {
//        return [
//            'name.*' => '商品标签名必须是唯一的字符串'
//        ];
//    }
}
